#!/bin/bash

read -p "请输入要查询的进程名：" process_name

process_info=$(ps -o pid= -o comm= -o user= -o %cpu= -o %mem= -o start= -o time= -o stat= -o vsz= -o rss= -C "$process_name")

if [ -z "$process_info" ]; then
    echo "该进程名没有运行！"
    exit
fi

echo -e "\e[32m***************************************************************\e[0m"
while read -r process_pid process_command process_user process_cpu process_mem process_start process_time process_stat process_vsz process_rss; do
    echo "进程PID: $process_pid"
    echo "进程命令：$process_command"
    echo "进程所属用户: $process_user"
    echo "CPU占用率：$process_cpu%"
    echo "内存占用率：$process_mem%"
    echo "进程开始运行的时间：$process_start"
    echo "进程运行的时间：$process_time"
    echo "进程状态：$process_stat"
    echo "进程虚拟内存：$process_vsz"
    echo "进程共享内存：$process_rss"
    echo -e "\e[32m***************************************************************\e[0m"
done <<< "$process_info"